Public Class frmMANAGEMENT
    Public Action As Integer = 0
    Public BILLCODE As Integer = 0
    Public ITEMCODE As String = ""

    Private Sub btnItemSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnItemSearch.Click
        Dim frm As New frmSEARCH_ITEM
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            If frm.GridItem.CurrentRow Is Nothing Then Me.Close()
            Action = 2
            ITEMCODE = frm.GridItem.GetValue("ITEM_CODE")
            Me.Close()
        End If
    End Sub

    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
        Me.Close()
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        Application.Exit()
    End Sub

    Private Sub btnLogOut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogOut.Click
        Dim frm As New Form
        For i As Integer = My.Application.OpenForms.Count - 1 To 0 Step -1
            If My.Application.OpenForms.Item(i).Name = "frmLOGIN" Then
                frm = My.Application.OpenForms.Item(i)
            Else
                My.Application.OpenForms.Item(i).Dispose()
            End If
        Next i
        frm.Show()
    End Sub

    Private Sub btnCustomerSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCustomerSearch.Click
        Dim frm As New frmSEARCH_CUSTOMER
        frm.btnSelect.Visible = False
        frm.ShowDialog()
    End Sub

    Private Sub btnCashFlow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCashFlow.Click
        Dim frm As New frmCASH
        frm.ShowDialog()
    End Sub

 

    Private Sub btnToGoList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToGoList.Click
        Dim frm As New frmTOGOLIST
        If frm.ShowDialog() = Windows.Forms.DialogResult.OK Then
            If frm.GridRecall.CurrentRow Is Nothing Then Me.Close()
            Action = 1
            BILLCODE = frm.GridRecall.GetValue("BILL_CODE")
            Me.Close()
        End If
    End Sub

    Private Sub btnSalesSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalesSearch.Click
        Dim frm As New frmRECALL
        frm.ShowDialog()
    End Sub



    Private Sub btnReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReport.Click
        Dim frm As New frmQUICK_REPORT
        frm.ShowDialog()
    End Sub

    Private Sub btnReceive_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnReceive.Click
        Dim frm As New frmSYNCHRONIZE
        frm.ShowDialog()
    End Sub

    Private Sub btnKeepingList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnKeepingList.Click
        Dim frm As New frmKEEPING_LIST
        frm.ShowDialog()
    End Sub

    Private Sub btnLockScreen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLockScreen.Click
        Dim frm As New frmUNLOCK
        frm.txtUser.Text = PublicVariable.UserName
        frm.txtUser.Enabled = False
        Me.Close()
        frm.ShowDialog()
    End Sub

    Private Sub btnDelivery_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelivery.Click
        Dim frm As New frmSEARCH_DELIVERY
        frm.ShowDialog()
    End Sub

    Private Sub btnAttendance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAttendance.Click
        Dim frm As New frmATTENDANCE
        frm.ShowDialog()
    End Sub

    Private Sub btnSubItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Dim frm As New frmSUBITEM
        If frm.ShowDialog = Windows.Forms.DialogResult.OK Then
            Me.Close()
        End If

    End Sub

    Private Sub btnQuickReservation_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnQuickReservation.Click
        Dim frm As New frmQUICK_RESERVATION
        frm.ShowDialog()
    End Sub

    Private Sub btnConfigure_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConfigure.Click
        Dim frm As New frmPWD
        frm.ShowDialog()
    End Sub

    Private Sub frmMANAGEMENT_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
        Try
            GC.Collect()
            Me.Dispose()
        Catch ex As Exception

        End Try
    End Sub

    Private Sub frmMANAGEMENT_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        PublicFunction.NewFormLoad(Me)
        RefreshStatus()
    End Sub

    Private Sub btnSalesDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalesDate.Click
        Dim frm As New frmCalendar
        frm.ShowDialog()
        PublicVariable.SystemDate = frm.Calendar2.SelectionRange.Start
    End Sub

    Private Sub btnShiftChange_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShiftChange.Click
        Dim frm As New frmSHIFTCHANGE
        Me.Close()
        frm.ShowDialog()
    End Sub


    Private Sub btnToGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnToGo.Click
        Dim FRM As New frmRECHARGE
        FRM.ShowDialog()
    End Sub

    Private Sub btnUnRegister_Click(sender As System.Object, e As System.EventArgs) Handles btnUnRegister.Click
        Dim a As New ServiceController("TotalPOS2SAP")
        Dim sReturn As String
        sReturn = a.Unregister()
        If sReturn = "" Then
            MessageBox.Show("UnRegister Sucessfull!")
        Else
            MessageBox.Show("Error: " + sReturn)
        End If
        RefreshStatus()
    End Sub

    Private Sub btnRegister_Click(sender As System.Object, e As System.EventArgs) Handles btnRegister.Click
        Dim a As New ServiceController("TotalPOS2SAP")
        a.Description = "TotalPOS2SAP"
        a.DisplayName = "TotalPOS2SAP"
        a.ServiceName = "TotalPOS2SAP"
        a.StartupType = ServiceController.ServiceStartupType.Automatic

        Dim sReturn As String
        sReturn = a.Register(Application.ExecutablePath + " -service")
        If sReturn = "" Then
            MessageBox.Show("Register Sucessfull!")
        Else
            MessageBox.Show("Error: " + sReturn)
        End If
        RefreshStatus()
    End Sub

    Private Sub btnStartService_Click(sender As System.Object, e As System.EventArgs) Handles btnStartService.Click
        Dim a As New ServiceController("TotalPOS2SAP")
        Dim str As String
        str = a.Start()
        RefreshStatus()
    End Sub

    Private Sub btnStopService_Click(sender As System.Object, e As System.EventArgs) Handles btnStopService.Click
        Dim a As New ServiceController("TotalPOS2SAP")
        Dim str As String = a.Stop()
        RefreshStatus()
    End Sub
    Private Sub RefreshStatus()
        Dim a As New ServiceController("TotalPOS2SAP")
        If a.Status = "" Then
            btnRegister.Enabled = True
            btnUnRegister.Enabled = False
            btnStartService.Enabled = False
            btnStopService.Enabled = False
        ElseIf a.Status = "Stopped" Then
            btnStartService.Enabled = True
            btnStopService.Enabled = False
            btnRegister.Enabled = False
            btnUnRegister.Enabled = True
        ElseIf a.Status = "Running" Then
            btnStartService.Enabled = False
            btnStopService.Enabled = True
            btnRegister.Enabled = False
            btnUnRegister.Enabled = True
        End If
    End Sub
End Class